// https://leetcode.cn/problems/zero-matrix-lcci/
// Created by ade on 2022/9/30.
//
#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    void setZeroes(vector <vector<int>> &matrix) {
        int row = matrix.size();
        int col = matrix[0].size();
        vector<int> rows(row);
        vector<int> cols(col);
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                if (matrix[i][j] == 0) {
                    rows[i] = 1;
                    cols[j] = 1;
                }
            }
        }

        for (int i = 0; i < row; i++) {
            cout << rows[i] << ",";
            if (rows[i] == 1) {
                for (int j = 0; j < col; j++) {
                    matrix[i][j] = 0;
                }
            }
        }
        cout << endl;
        for (int i = 0; i < col; i++) {
            cout << cols[i] << ",";
            if (cols[i] == 1) {
                for (int j = 0; j < row; j++) {
                    matrix[j][i] = 0;
                }
            }
        }
        cout << endl;
    }
};

int main() {
    Solution so;
    vector <vector<int>> matrix = {{0, 1, 2, 0},
                                   {3, 4, 5, 2},
                                   {1, 3, 1, 5}};
    so.setZeroes(matrix);
    for (int i = 0; i < matrix.size(); i++) {
        for (int j = 0; j < matrix[0].size(); j++) {
            cout << matrix[i][j] << ",";
        }
        cout << endl;
    }
    return 0;
}